package gamehistory.challenge;

import scg.gen.OfferTrans;
import scg.gen.ReofferTrans;
import utils.FormatUtilities;
import gamehistory.utils.xml.XMLModel;

public class OfferModel extends XMLModel {
	
	private static final String OFFER						  = "offer";
	private static final String OFFERED  			    	  = "offered";
	private static final String REOFFERED					  = "reoffered";
	
	private static final String PLAYER	  			    	  = "player";
	private static final String PRICE	  			    	  = "price";
	private static final String TYPE						  = "type";
	private static final String DECREMENT_FROM_PREVIOUS_PRICE = "decFromPreviousPrice";
	
	private String playerName;
	private String type;
	private double price;
	private double decFromPreviousPrice;
	
	/**
	 * Constructor for original offers.
	 * @param playerName
	 * @param offer
	 */
	public OfferModel(String playerName, OfferTrans offer) {
		super(OFFER);
		this.playerName 		  = playerName;
		this.type 	    		  = OFFERED;
		this.price  			  = offer.getPrice();
		this.decFromPreviousPrice = 0.0d;
	}
	
	/**
	 * Constructor for reoffers.
	 * @param playerName
	 * @param offer
	 * @param previousPrice
	 */
	public OfferModel(String playerName, ReofferTrans offer, double previousPrice) {
		super(OFFER);
		this.playerName 		  = playerName;
		this.type 	    		  = REOFFERED;
		this.price  			  = offer.getPrice();
		this.decFromPreviousPrice = previousPrice - this.price;
	}
	
	/**
	 * Gets the player name for this offer model.
	 * @return
	 */
	public String getPlayerName() {
		return playerName;
	}

	/**
	 * Gets the offer type for this offer model.
	 * @return
	 */
	public String getType() {
		return type;
	}

	/**
	 * Gets the price for this offer model.
	 * @return
	 */
	public double getPrice() {
		return price;
	}

	/**
	 * Gets the price decrement from the previous price of this offer model.
	 * @return The decrement from previous price, or 0 if this is an original offer.
	 */
	public double getDecFromPreviousPrice() {
		return decFromPreviousPrice;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void buildModel() {
		addAttribute(TYPE,   						this.type);
		addAttribute(PLAYER, 						this.playerName);
		addAttribute(PRICE,  						FormatUtilities.formatDouble(this.price));
		addAttribute(DECREMENT_FROM_PREVIOUS_PRICE, FormatUtilities.formatDouble(this.decFromPreviousPrice));
	}
}
